package jwdt.wizards;

import java.util.HashMap;
import java.util.Map;

import jwdt.common.Constant;
import jwdt.popup.actions.InitProFrameWorkAction;

import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class InitProFrameWorkWizardPage_1 extends WizardPage {
	
	private ISelection selection;

	private Map<String,String> fws = new HashMap<String,String>();
	
	public Map<String, String> getFws() {
		return fws;
	}
	
	//事件
	SelectionListener selectionListener = new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			Button btn = (Button) e.getSource();
			if(btn.getParent() instanceof Group){
				Group g = (Group)btn.getParent();
				fws.put(g.getText(),btn.getText());
			}				
		}
	};
	
	/**
	 * Constructor for SampleNewWizardPage.
	 * 
	 * @param pageName
	 */
	public InitProFrameWorkWizardPage_1(ISelection selection) {
		super("wizardPage");
		setTitle("InitProFrameWork");
		setDescription("for Dynamic Web Project(2.4/2.5) - FrameWork.");
		
		this.selection = selection;
		
		fws.put(Constant.PAGE, Constant.PAGE_JEASYUI);
		fws.put(Constant.MVC, Constant.MVC_SPRINGMVC);
		fws.put(Constant.IOC, Constant.IOC_SPRING);
		fws.put(Constant.ORM, Constant.ORM_IBATIS);
		fws.put(Constant.PUBLIC_LIBS, Constant.PUBLIC_LIBS);
	}

	/**
	 * @see IDialogPage#createControl(Composite)
	 */
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);
		
		GridLayout container_layout = new GridLayout();
		container_layout.numColumns = 1;
		container_layout.makeColumnsEqualWidth = true;
		container_layout.verticalSpacing=9;
		container.setLayout(container_layout);		
						
		Composite proInfo = new Composite(container, SWT.NONE);
		proInfo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		GridLayout proInfo_layout = new GridLayout();
		proInfo_layout.numColumns = 2;
		proInfo_layout.makeColumnsEqualWidth = false;
		proInfo_layout.verticalSpacing=9;
		proInfo.setLayout(proInfo_layout);	
		
		Label label_proName = new Label(proInfo, SWT.NONE);		
		label_proName.setText("Project name：");
		label_proName.setLayoutData(new GridData(GridData.BEGINNING));
		
		Text proNameText = new Text(proInfo,SWT.BORDER | SWT.SINGLE);
		proNameText.setEditable(false);
		proNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		proNameText.setText(InitProFrameWorkAction.projectProperties.getProjectName());
		
		Label label_moduleVersion = new Label(proInfo, SWT.NONE);		
		label_moduleVersion.setText("Module version：");
		label_moduleVersion.setLayoutData(new GridData(GridData.BEGINNING));
		
		Text moduleVersionText = new Text(proInfo,SWT.BORDER | SWT.SINGLE);
		moduleVersionText.setEditable(false);
		moduleVersionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		moduleVersionText.setText(InitProFrameWorkAction.projectProperties.getModuleVersion());
		
		/*
		Composite proVer = new Composite(container, SWT.NONE);
		proVer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
				
		GridLayout proVer_layout = new GridLayout();
		proVer_layout.numColumns = 2;
		proVer_layout.makeColumnsEqualWidth = false;
		proVer_layout.verticalSpacing=9;
		proVer.setLayout(proVer_layout);	
				
		Label label_wmv = new Label(proVer, SWT.NONE);		
		label_wmv.setText("Dynamic web module version：");
		label_wmv.setLayoutData(new GridData(GridData.BEGINNING));
		
		Text label_wmv_Text = new Text(proVer,SWT.BORDER | SWT.SINGLE);
		label_wmv_Text.setText("mywebppro");
		label_wmv_Text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		*/

		/**
		 * MVC
		 */
		Group groupMVC = new Group(container,SWT.NONE);
		groupMVC.setText(Constant.MVC);
		
		GridLayout groupMVC_layout = new GridLayout();
		groupMVC_layout.numColumns = 3;
		groupMVC_layout.makeColumnsEqualWidth = true;
		groupMVC.setLayout(groupMVC_layout);		
		groupMVC.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
						
		Button struts = new Button(groupMVC,SWT.RADIO);
		struts.setText(Constant.MVC_STRUTS);
		struts.setLayoutData(new GridData(GridData.FILL_BOTH));
		struts.setEnabled(false);
		struts.addSelectionListener(selectionListener);
		
		Button struts2 = new Button(groupMVC,SWT.RADIO);
		struts2.setText(Constant.MVC_STRUTS2);
		struts2.setLayoutData(new GridData(GridData.FILL_BOTH));
		struts2.setEnabled(true);
		struts2.addSelectionListener(selectionListener);
		
		Button springMVC = new Button(groupMVC,SWT.RADIO);
		springMVC.setText(Constant.MVC_SPRINGMVC);
		springMVC.setSelection(true);
		springMVC.setLayoutData(new GridData(GridData.FILL_BOTH));
		springMVC.addSelectionListener(selectionListener);
		/**
		 * IOC
		 */
		Group groupIOC = new Group(container,SWT.FILL);
		groupIOC.setText(Constant.IOC);
		
		GridLayout groupIOC_layout = new GridLayout();
		groupIOC_layout.numColumns = 3;
		groupIOC_layout.makeColumnsEqualWidth = true;
		groupIOC.setLayout(groupIOC_layout);		
		groupIOC.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		Button spring = new Button(groupIOC,SWT.RADIO);
		spring.setText(Constant.IOC_SPRING);
		spring.setSelection(true);
		spring.setLayoutData(new GridData(GridData.FILL_BOTH));
		spring.addSelectionListener(selectionListener);
		/**
		 * ORM
		 */
		Group groupORM = new Group(container,SWT.FILL);
		groupORM.setText(Constant.ORM);

		GridLayout groupORM_layout = new GridLayout();
		groupORM_layout.numColumns = 3;
		groupORM_layout.makeColumnsEqualWidth = true;
		groupORM.setLayout(groupORM_layout);		
		groupORM.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
				
		Button hibernate = new Button(groupORM,SWT.RADIO);
		hibernate.setText(Constant.ORM_HIBERNATE);		
		hibernate.setLayoutData(new GridData(GridData.FILL_BOTH));
		hibernate.setEnabled(true);
		hibernate.addSelectionListener(selectionListener);
		
		Button ibatis = new Button(groupORM,SWT.RADIO);
		ibatis.setText(Constant.ORM_IBATIS);
		ibatis.setSelection(true);
		ibatis.setLayoutData(new GridData(GridData.FILL_BOTH));
		ibatis.addSelectionListener(selectionListener);
		
		/**
		 * PAGE
		 */
		Group groupPAGE = new Group(container,SWT.FILL);
		groupPAGE.setText(Constant.PAGE);
		
		GridLayout groupPAGE_layout = new GridLayout();
		groupPAGE_layout.numColumns = 3;
		groupPAGE_layout.makeColumnsEqualWidth = true;
		groupPAGE.setLayout(groupPAGE_layout);		
		groupPAGE.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		Button extjs = new Button(groupPAGE,SWT.RADIO);
		extjs.setText(Constant.PAGE_EXTJS);		
		extjs.setLayoutData(new GridData(GridData.FILL_BOTH));
		extjs.setEnabled(false);
		extjs.addSelectionListener(selectionListener);
		
		Button jeasyui = new Button(groupPAGE,SWT.RADIO);
		jeasyui.setText(Constant.PAGE_JEASYUI);		
		jeasyui.setLayoutData(new GridData(GridData.FILL_BOTH));
		jeasyui.setSelection(true);
		jeasyui.addSelectionListener(selectionListener);
		
		/**
		 * DataSource
		 */
		/*
		Button dataSource = new Button(container,SWT.CHECK);
		dataSource.setText("多数据源");
		dataSource.setSelection(false);
		dataSource.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		*/
		
		setControl(container);
	}
}